// pages/afterSaleCente/afterSaleCente.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: 0,
    choose: 0,
    count: 1,
    choo_modal: "none"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var card = JSON.parse(options.card);
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight,
      card:card
    })
    wx.request({
      url: app.globalData.url + '',
      method: 'GET',
      data: {

      },
      success: function (res) {
        that.setData({

        });
      },
    });
    //分享banner
    wx.request({
      url: app.globalData.url + "getAdvertisementListByType?advertisingType=9",
      method: "GET",
      data: {
      },
      success: function (res) {
        var data = res.data.data;
        if (res.data.result == 1) {
          var link = [];
          for (var i = 0; i < data.length; i++) {
            var link0 = data[i].link;
            var a = link0.substr(link0.length - 1);
            data[i].linkType = a;
          }
          that.setData({
            mallBanner: data,
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  navBack: function () {
    wx.navigateBack({
    })
  },
  goHR: function () {
    wx.navigateTo({
      url: '/pages/storedValueCardHR/storedValueCardHR',
    })
  },
  // 弹出
  modal_s: function (e) {
    this.setData({
      choo_modal: "block"
    });
  },
  //消失
  modal_n: function () {
    this.setData({
      choo_modal: "none"
    });
  },
  goOut: function () {
    this.setData({
      choo_modal: "none"
    });
    var that = this;
    wx.request({
      url: app.globalData.url + 'refundStoredValueCard',
      method: 'GET',
      data: {
        userId: wx.getStorageSync("userId"),
        cardId: that.data.card.cardId
      },
      success: function (res) {
        that.navBack();
      },
    });
  },
  addMoney: function() {
    var that = this;
    wx.request({
      url: app.globalData.url + 'userUsedStoredValueCard',
      method: 'GET',
      data: {
        userId: wx.getStorageSync("userId"),
        cardId: that.data.card.cardId
      },
      success: function (res) {
        that.navBack();
      },
    });
  },
  /**
  * 页面分享
  */
  onShareAppMessage: function (e) {
    var that = this;
    console.info(that.data.mallBanner);
    return {
      title: '极味生鲜',
      desc: '储值卡赠送',
      imageUrl: that.data.mallBanner[0].imageURL,
      path: '/pages/mallPage/mallPage?partnerUserId=' + wx.getStorageSync("userId") + '&giving=2&cardid=' + that.data.card.cardId + '&partnerUserName=' + wx.getStorageSync("nickName") + '&price=' + that.data.card.value, // 路径，传递参数到指定页面
      success(res) {

      }
    }
  },
})